<template>
	<view class="content bg-light">
		<tabsTop tabName=" "></tabsTop>
		<view class="" style="min-height: 578px;background-color: #f2f2f2;">
			<!-- 图标和tab -->
			<view class="fixed-element bg-light">
				<view class="icon-tab-container p-2">
					<image class="icon rounded-circle" :src="Domain_ICON+'/sponsor.jpg'" mode="aspectFit"></image>
					<text class="tab-text">小康龙江</text>
				</view>
				<view class="tab-bar p-1">
					<text class="tab-item" :class="{ 'active': currentTab === 'balance' }"
						@click="switchTab('balance')">余额</text>
					<text class="tab-item" :class="{ 'active': currentTab === 'giftCard' }"
						@click="switchTab('giftCard')">礼品卡</text>
					<view class="tab-indicator" :style="{ left: leftPosition, width: tabWidth }"></view>
				</view>
			</view>
			<!-- 余额 -->
			<view v-show="currentTab === 'balance'">
				<view class="m-2 bg-white"
					style="margin-top: 100px;border-bottom-left-radius: 10px;border-bottom-right-radius: 10px;">
					<view class="d_balance p-1">
						<view class="m-1" style="font-size: 11px;">店铺余额</view>
						<view class="flex align-center m-1">￥<view style="font-size: 23px;">{{balance}}</view>
						</view>
					</view>
					<view class="flex align-center" style="font-size: 10px;height: 37px;">
						<view class="principal ml-2">本金 ￥{{principal}}</view>
						<view class="ml-2">赠送金 ￥{{gifts}}</view>
					</view>
				</view>
				<!-- 立即充值 -->
				<view>
					<button class="recharge flex align-center justify-center" @click="goRecharge">立即充值</button>
				</view>
				<!-- 使用帮助 -->
				<view>
					<view class="flex justify-between align-center p-3" @click="goTranHistory">
						<view style="font-size: 12px;">消费记录</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
					<view class="flex justify-between align-center p-3">
						<view style="font-size: 12px;">有效期</view>
						<view style="font-size: 12px;">永久有效</view>
					</view>
					<view class="flex justify-between align-center p-3" @click="goHelp">
						<view style="font-size: 12px;">使用帮助</view>
						<uni-icons type="right" size="16"></uni-icons>
					</view>
				</view>
			</view>
			<!-- 礼品卡 -->
			<view v-show="currentTab === 'giftCard'">
				<!-- 兑换和购买 -->
				<view class="trade-in flex align-center bg-white m-2">
					<view class="exchange flex">
						<image :src="D+''"></image>
						<view>兑换</view>
					</view>
					<view class="flex">
						<image></image>
						<view>购买礼品卡</view>
					</view>
				</view>
				<!-- 暂无礼品卡 -->
				<view>
					<view class="nogifts">暂无礼品卡</view>
				</view>
				<!-- 去购买 -->
				<view>
					<button class="gobuy flex align-center justify-center">去购买</button>
				</view>
				<!-- 查看明细 -->
				<view>
					<view class="fixed-button shadow bg-white" @click="goGiftDetails">查看明细</view>
				</view>
			</view>
		</view>
		<!-- 底部赞助信息 -->
		<botSponsor></botSponsor>
	</view>
</template>

<script>
	const app = getApp();
	import tabsTop from "@/components/tabs/tabs-top.vue";
	import botSponsor from "@/components/botsponsor/sponsor.vue"
	export default {
		components: { //轮播图组件
			tabsTop,
			botSponsor // 底部赞助商
		},
		data() {
			return {
				currentTab: 'balance',
				tabs: ['balance', 'giftCard'], // 选项卡数组
				balance: 0,
				principal: 0,
				gifts: 0,
				Domain_ICON: app.globalData.Domain_ICON
			}
		},
		computed: {
			leftPosition() {
				return `calc(${this.tabs.indexOf(this.currentTab) * (31 / this.tabs.length)}% + 3%)`; // 设置 left 样式，初始值为 5%
			},
			tabWidth() {
				return `calc(18% / ${this.tabs.length})`; // 设置选项卡宽度
			}
		},
		onReady() {

		},
		onLoad() {

		},
		methods: {
			switchTab(tab) {
				this.currentTab = tab;
			},
			goGiftDetails() {
				uni.navigateTo({
					url: "/pages/my/giftDetails",
				})
			},
			goRecharge() {
				uni.navigateTo({
					url: "/pages/my/recharge?balance=" + encodeURIComponent(this.balance),
				})
			},
			goTranHistory(){
				uni.navigateTo({
					url: "/pages/my/tranHistory",
				})
			},
			goHelp(){
				uni.navigateTo({
					url: "/pages/my/help",
				})
			}
		}
	}
</script>

<style>
	.fixed-element {
		position: fixed;
		top: 63px;
		left: 0;
		width: 100%;
		z-index: 999;
	}

	.icon-tab-container {
		display: flex;
		align-items: center;
	}


	.tab-text {
		margin-left: 10px;
		font-size: 10px;
		font-weight: bold;
	}

	.tab-bar {
		display: flex;
		border-bottom: 1px solid #ccc;
	}

	.tab-item {
		text-align: center;
		padding: 10px;
		font-size: 14px;
		cursor: pointer;
	}

	.active {
		color: #007BFF;
	}

	.tab-indicator {
		position: absolute;
		top: 86px;
		left: 0;
		height: 4px;
		background-color: #00bfff;
		transition: left 0.3s;
	}

	.d_balance {
		background-color: #09b720;
		border-radius: 10px;
		height: 80px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		color: white;
	}

	.principal {
		width: 50%;
	}

	.principal::after {
		content: "|";
		margin-left: 70%;
		color: #ebedf0;
	}

	.recharge {
		width: 35%;
		margin: auto;
		background-color: #09bb07;
		color: white;
		height: 35px;
		font-size: 11px;
		border-radius: 20px;
		margin-top: 40px;
	}

	.icon {
		width: 20px;
		height: 20px;
	}

	.trade-in {
		justify-content: space-around;
		height: 33px;
		font-size: 14px;
		border-radius: 14px;
		margin-top: 100px;
	}

	.exchange::after {
		content: "|";
		margin-left: 54px;
		margin-right: -105px;
	}

	image {
		width: 20px;
		height: 20px;
	}

	.nogifts {
		font-size: 13px;
		text-align: center;
		margin-top: 180px;
		color: #9d9d9d;
	}

	.gobuy {
		width: 35%;
		margin: auto;
		background-color: #09bb07;
		color: white;
		height: 35px;
		font-size: 11px;
		border-radius: 20px;
		margin-top: 40px;
	}

	.fixed-button {
		position: fixed;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		padding: 10px 20px;
		cursor: pointer;
		width: 100%;
		text-align: center;
		font-size: 12px;
	}
</style>